package com.z6school.manage.controller;

import com.z6school.manage.common.pojo.JsonResult;
import com.z6school.manage.mapper.RolesMapper;
import com.z6school.manage.po.Role;
import com.z6school.manage.po.User;
import com.z6school.manage.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/role/")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping("doFindObject")
    public JsonResult doFindObject(String name,int pageCurrent){
        return  new JsonResult(roleService.doFindObject(name,pageCurrent));
    }

    @RequestMapping("doDeleteObject")
    public JsonResult doDeleteObject(Integer id){
        roleService.deleteObject(id);
        return new JsonResult("删除成功");
    }

    @RequestMapping("doSaveObject")
    public JsonResult doSaveObject(Role entity,Integer[] menuIds){
        roleService.saveObject(entity, menuIds);
        return new JsonResult("保存成功");
    }

    @RequestMapping("doFindRoleMenuById")
    public JsonResult doFindRoleMenuById(Integer id){
        return new JsonResult(roleService.findRoleMenuById(id));
    }

    @RequestMapping("doUpdateObject")
    public JsonResult doUpdateObject(Role role,Integer[] menuIds){
        roleService.updateObject(role, menuIds);
        return new JsonResult("更新成功");
    }

    /**查询角色id，name相关信息*/
    @RequestMapping("doFindRoles")
    public JsonResult doFindRoles(){
        return new JsonResult(roleService.findCheckBoxObjects());
    }


}
